package com.zyt.controller;

import com.zyt.pojo.Category;
import com.zyt.pojo.Tea;
import com.zyt.service.CategoryService;
import com.zyt.service.TeaService;
import com.zyt.service.impl.CategoryServiceImpl;
import com.zyt.service.impl.TeaServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
@Controller
public class CategoryController {
    CategoryService categoryService = new CategoryServiceImpl();
    @RequestMapping("/selectAllCategory")
    public String selectAl(Model model){
        List<Category> categoryList = categoryService.selectAllCategory();
        model.addAttribute("categoryList",categoryList);
        categoryList.forEach(System.out::println);
        return "/addTea.jsp";
    }
    @RequestMapping("/selectAllCategory1")
    public String selectAll(Model model){
        List<Category> categoryList = categoryService.selectAllCategoryAndTea();
        model.addAttribute("categoryList",categoryList);
        categoryList.forEach(System.out::println);
        return "/categorylist.jsp";
    }
    TeaService teaService =new TeaServiceImpl();
    @RequestMapping("/deleteTeaAndCateController")
    public String deleteController(Integer id) {
        teaService.deleteByIdAndCate(id);
        categoryService.deleteByIdAndC(id);
        return "/selectAllCategory1.do";
    }
}
